﻿{extend name="public:base" /}

{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">
{/block}
{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">微信用户手机号</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control wx_mobile" maxlength="11" placeholder="请输入微信用户手机号">
                                </div>
                            </div>
                        </div>
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">微信昵称</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control wx_nickname" placeholder="" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">姓名</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control wx_username" placeholder="" readonly>
                                </div>
                            </div>
                            <input type="hidden" class="wx_id" value="0">
                            <div class="hr-line-dashed"></div>
                        </div>


                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">资料用户手机号</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control excel_mobile" maxlength="11" placeholder="请输入资料用户手机号">
                                </div>
                            </div>
                        </div>
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">姓名</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control excel_username" placeholder="" readonly>
                                </div>
                            </div>
                            <input type="hidden" class="excel_id" value="0">
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-primary bind_user">确认绑定</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name='js'}
<script>
    $('.wx_mobile').on('input', function () {
        var mobile = $(this).val();

        if (mobile.length == 11) {
            $.post("{:url('/admin/manage/bindUser')}", {mobile, type: 1}, res => {
                if (res.result == 1) {
                    $('.wx_nickname').val(res.data.nickname);
                    $('.wx_username').val(res.data.username);
                    $('.wx_id').val(res.data.id);
                } else {
                    $('.wx_nickname').val('');
                    $('.wx_username').val('');
                    $('.wx_id').val(0);
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
        }
    });

    $('.excel_mobile').on('input', function () {
        var mobile = $(this).val();

        if (mobile.length == 11) {
            $.post("{:url('/admin/manage/bindUser')}", {mobile, type: 2}, res => {
                if (res.result == 1) {
                    $('.excel_username').val(res.data.username);
                    $('.excel_id').val(res.data.id);
                } else {
                    $('.excel_username').val('');
                    $('.excel_id').val(0);
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
        }
    })

    $('.bind_user').click(() => {
        var wx_id = $('.wx_id').val();
        var excel_id = $('.excel_id').val();

        if (wx_id == 0 || excel_id == 0) {
            layer.msg('请输入正确的手机号', {icon: 2});
        } else {
            $.post("{:url('/admin/manage/bindUser')}", {wx_id, excel_id, is_bind: 1}, res => {
                if (res.result == 1) {
                    layer.msg(res.msg, {icon: 1, end: () => {
                        window.location.reload();
                    }});
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json')

        }

    })
</script>{/block}
